

#import "CheckBox.h"

@implementation CheckBox

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self initilization];
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)aCoder {
    if (self = [super initWithCoder:aCoder]) {
        [self initilization];
    }
    return self;
}

- (void)initilization {
    [self removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
    [self addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)onClick: (id)sender {
    if (self.selected) {
		[self setImage:[UIImage imageNamed:@"checkbox_off.png"] forState:UIControlStateNormal];
	}
	else {
		[self setImage:[UIImage imageNamed:@"checkbox_on.png"] forState:UIControlStateNormal];
	}
    self.selected = ![self isSelected];
}

- (void)onSelected:(id)sender
{
    [self setImage:[UIImage imageNamed:@"checkbox_on.png"] forState:UIControlStateNormal];
    self.selected = YES;
}

- (void)offSelected:(id)sender
{
    [self setImage:[UIImage imageNamed:@"checkbox_off.png"] forState:UIControlStateNormal];
    self.selected = NO;
}

@end